Web Services

Update an Existing Record Using External Web Service

Description
This customization shows how to use a web service to update data from a web service-based data source. This provides an alternate way to access data than the database stored procedure and inline SQL normally generated by Iron Speed Designer.
Variables
Table Name
Select the database table
Primary Key
Select the primary key field in the table
First Updatable Field
Select an updatable field in the table
Second Updatable Field
Select another updatable field in the table
Applies to
SQLAccessClass class
Code
 
/// 
/// UpdateRecord makes use of Web Service to update a record.
/// 
/// The table to update a record in.
/// The id used to identify the record that will be updated.
/// Function
/// Nothing, or the new  of the inserted record.
public override void UpdateRecord(
  BaseClasses.Data.TableDefinition table, 
  BaseClasses.Data.KeyValue recordId, 
  BaseClasses.Data.RecordValue recValue, 
  bool[] columnsChanged) 
  { 
      int ${Primary Key} = -1; 
      string ${First Updatable Field} = ""; 
      string ${Second Updatable Field} = ""; 

      // Get the instance of the data access class.
      ${${Table Name}ClassName} myTable; 
      myTable = ${${Table Name}ClassName}.Instance; 

      foreach (BaseClasses.Data.BaseColumn col in table.ColumnList) 
      { 
          int index = table.ColumnList.IndexOf(col); 
          if (col.InternalName == myTable.${First Updatable Field}Column.InternalName) 
          { 
              // Set value of ${First Updatable Field}.
              ${First Updatable Field} = col.ToDatabaseValue(recValue.ColumnValues[index]).ToString(); 
          } 
          else if (col.InternalName == myTable.${Second Updatable Field}Column.InternalName) 
          { 
              // Set value of ${Second Updatable Field}.
              ${Second Updatable Field} = col.ToDatabaseValue(recValue.ColumnValues[index]).ToString(); 
          } 
          else if (col.InternalName == myTable.${Primary Key}Column.InternalName) 
          { 
              // Set value of ${Primary Key}.
              ${Primary Key} = System.Convert.ToInt32(col.ToDatabaseValue(recValue.ColumnValues[index]).ToString()); 
          } 
      } 

      // Instantiate the object that will communicate with a web service.
      // Replace MyWebServiceForTableAccess with the external Web Service name
      localhost.MyWebServiceForTableAccess webService; 
      webService = new localhost.MyWebServiceForTableAccess(); 
      webService.Credentials = System.Net.CredentialCache.DefaultCredentials; 

      // Call the web service's "UpdateRecord" function.
      webService.Update${${Table Name}RecordClassName}(${Primary Key}, ${First Updatable Field}, ${Second Updatable Field}); 
  }
     

Terms of Service Privacy Statement